home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / ASM32PM.ZIP / FILE.ASM < prev    next >
Assembly Source File  |  1993-06-07  |  11KB  |  476 lines

  1. ; OPENFILE              = 1
  2. ; READFILE              = 1
  3. ; WRITEFILE             = 1
  4. ; LSEEKFILE             = 1
  5. ; CREATEFILE            = 1
  6. ; FILESIZE              = 1
  7. ; FILECOPY              = 1
  8. ; DELETEFILE            = 1
  9. ; FINDFILE              = 1
  10.         .386p
  11. code32  segment para public use32
  12.         assume cs:code32, ds:code32
  13.  
  14. include pmode.inc
  15.  
  16. public  _filebufloc, _filebuflen
  17. public  _closefile
  18.  
  19. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  20. ; DATA
  21. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  22. _filebufloc     dd      0               ; location must be in low mem
  23. _filebuflen     dw      4000h
  24.  
  25. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  26. ; CODE
  27. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  28.  
  29. ifdef   CREATEFILE
  30. public  _createfile
  31. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  32. ; Create file
  33. ; In:
  34. ;   EDX -> ASCIIZ filename
  35. ; Out:
  36. ;   CF=1 - Error creating file
  37. ;   CF=0 - File created succesfully
  38. ;     V86R_BX - file handle
  39. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  40. _createfile:
  41.         push ax
  42.         push edx
  43.         add edx,_code32a
  44.         mov ax,dx
  45.         shr edx,4
  46.         and ax,0fh
  47.         mov v86r_dx,ax
  48.         mov v86r_ds,dx
  49.         mov v86r_ax,3c00h
  50.         mov v86r_cx,20h
  51.         mov al,21h
  52.         int 33h
  53.         mov ax,v86r_ax
  54.         mov v86r_bx,ax
  55.         pop edx
  56.         pop ax
  57.         ret
  58. endif
  59.  
  60. ifdef   OPENFILE
  61. public  _openfile
  62. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  63. ; Open file
  64. ; In:
  65. ;   EDX -> ASCIIZ filename
  66. ; Out:
  67. ;   CF=1 - Error opening file
  68. ;   CF=0 - File opened succesfully
  69. ;     V86R_BX - file handle
  70. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  71. _openfile:
  72.         push ax
  73.         push edx
  74.         add edx,_code32a
  75.         mov ax,dx
  76.         shr edx,4
  77.         and ax,0fh
  78.         mov v86r_dx,ax
  79.         mov v86r_ds,dx
  80.         mov v86r_ax,3d02h
  81.         mov al,21h
  82.         int 33h
  83.         mov ax,v86r_ax
  84.         mov v86r_bx,ax
  85.         pop edx
  86.         pop ax
  87.         ret
  88. endif
  89.  
  90. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  91. ; Close a file
  92. ; In:
  93. ;   V86R_BX - file handle
  94. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  95. _closefile:
  96.         push ax
  97.         mov v86r_ax,3e00h
  98.         mov al,21h
  99.         int 33h
  100.         pop ax
  101.         ret
  102.  
  103. ifdef   DELETEFILE
  104. public  _deletefile
  105. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  106. ; Delete a file
  107. ; In:
  108. ;   EDX -> ASCIIZ filename
  109. ; Out:
  110. ;   CF=1 - Error opening file
  111. ;   CF=0 - File opened succesfully
  112. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  113. _deletefile:
  114.         push ax
  115.         push edx
  116.         add edx,_code32a
  117.         mov ax,dx
  118.         shr edx,4
  119.         and ax,0fh
  120.         mov v86r_dx,ax
  121.         mov v86r_ds,dx
  122.         mov v86r_ah,41h
  123.         mov al,21h
  124.         int 33h
  125.         pop edx
  126.         pop ax
  127.         ret
  128. endif
  129.  
  130. ifdef   LSEEKFILE
  131. public  _lseekfile
  132. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  133. ; Seek position in file
  134. ; In:
  135. ;   V86R_BX - file handle
  136. ;   EAX - signed offset to move to
  137. ;   BL - from: 0-beginning of file, 1-current location, 2-end of file
  138. ; Out:
  139. ;   CF=1  - Error seeking in file
  140. ;     EAX - ?
  141. ;   CF=0  - Seek fine
  142. ;     EAX - new offset from beginning of file
  143. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  144. _lseekfile:
  145.         mov v86r_ah,42h
  146.         mov v86r_al,bl
  147.         mov v86r_dx,ax
  148.         shr eax,16
  149.         mov v86r_cx,ax
  150.         mov al,21h
  151.         int 33h
  152.         pushf
  153.         mov ax,v86r_dx
  154.         shl eax,16
  155.         mov ax,v86r_ax
  156.         popf
  157.         ret
  158. endif
  159.  
  160. ifdef   FILESIZE
  161. public  _filesize
  162. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  163. ; Get size of file
  164. ; In:
  165. ;   V86R_BX - file handle
  166. ; Out:
  167. ;   CF=1  - Error checking file
  168. ;     EAX - ?
  169. ;   CF=0  - chek fine
  170. ;     EAX - size of file
  171. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  172. _filesize:
  173.         mov v86r_ax,4201h
  174.         xor eax,eax
  175.         mov v86r_cx,ax
  176.         mov v86r_dx,ax
  177.         mov al,21h
  178.         int 33h
  179.         push v86r_dx
  180.         push v86r_ax
  181.         mov v86r_ax,4202h
  182.         xor eax,eax
  183.         mov v86r_cx,ax
  184.         mov v86r_dx,ax
  185.         mov al,21h
  186.         int 33h
  187.         mov ax,v86r_dx
  188.         shl eax,16
  189.         mov ax,v86r_ax
  190.         pop v86r_dx
  191.         pop v86r_cx
  192.         mov v86r_ax,4200h
  193.         push eax
  194.         mov al,21h
  195.         int 33h
  196.         pop eax
  197.         ret
  198. endif
  199.  
  200. ifdef   READFILE
  201. public  _readfile
  202. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  203. ; Read from file
  204. ; In:
  205. ;   V86R_BX - file handle
  206. ;   EDX -> buffer to read to
  207. ;   ECX - number of bytes to read
  208. ; Out:
  209. ;   CF=1 - Error reading file
  210. ;     EAX - ?
  211. ;   CF=0 - Read went fine
  212. ;     EAX - number of bytes read
  213. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  214. _readfile:
  215.         pushad
  216.         xor ebp,ebp
  217.         add edx,_code32a
  218.         lea ebx,[ecx+edx]
  219.         cmp ebx,100000h
  220.         ja readlong
  221.         mov eax,edx
  222.         shr eax,4
  223.         and dx,0fh
  224.         mov v86r_ds,ax
  225.         mov v86r_dx,dx
  226. readl:
  227.         mov eax,0fff0h
  228.         cmp eax,ecx
  229.         jbe readlf1
  230.         mov eax,ecx
  231. readlf1:
  232.         mov v86r_cx,ax
  233.         mov v86r_ax,3f00h
  234.         mov al,21h
  235.         int 33h
  236.         jc readdone2
  237.         movzx ebx,v86r_ax
  238.         add ebp,ebx
  239.         sub ecx,ebx
  240.         jbe readdone
  241.         or ebx,ebx
  242.         jz readdone
  243.         add v86r_ds,0fffh
  244.         jmp readl
  245. readlong:
  246.         mov edi,edx
  247.         sub edi,_code32a
  248.         mov edx,ecx
  249.         mov eax,_filebufloc
  250.         add eax,_code32a
  251.         mov ebx,eax
  252.         shr eax,4
  253.         and bx,0fh
  254.         mov v86r_ds,ax
  255.         mov v86r_dx,bx
  256.         movzx ebx,_filebuflen
  257. readlongl:
  258.         mov eax,ebx
  259.         cmp eax,edx
  260.         jbe readlonglf1
  261.         mov eax,edx
  262. readlonglf1:
  263.         mov v86r_cx,ax
  264.         mov v86r_ax,3f00h
  265.         mov al,21h
  266.         int 33h
  267.         jc short readdone2
  268.         movzx ecx,v86r_ax
  269.         add ebp,ecx
  270.         mov eax,ecx
  271.         or eax,eax
  272.         jz readdone
  273.         mov esi,_filebufloc
  274.         rep movsb
  275.         sub edx,eax
  276.         ja readlongl
  277. readdone:
  278.         clc
  279. readdone2:
  280.         mov [esp+28],ebp
  281.         popad
  282.         ret
  283. endif
  284.  
  285. ifdef   WRITEFILE
  286. public  _writefile
  287. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  288. ; Write to file
  289. ; In:
  290. ;   V86R_BX - file handle
  291. ;   EDX -> buffer to write from
  292. ;   ECX - number of bytes to write
  293. ; Out:
  294. ;   CF=1 - Error writing file
  295. ;     EAX - ?
  296. ;   CF=0 - Write went fine
  297. ;     EAX - number of bytes read
  298. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  299. _writefile:
  300.         pushad
  301.         xor ebp,ebp
  302.         add edx,_code32a
  303.         lea ebx,[ecx+edx]
  304.         cmp ebx,100000h
  305.         ja writelong
  306.         mov eax,edx
  307.         shr edx,4
  308.         and ax,0fh
  309.         mov v86r_ds,dx
  310.         mov v86r_dx,ax
  311. writel:
  312.         mov eax,0fff0h
  313.         cmp eax,ecx
  314.         jbe writelf1
  315.         mov eax,ecx
  316. writelf1:
  317.         mov v86r_cx,ax
  318.         mov v86r_ax,4000h
  319.         mov al,21h
  320.         int 33h
  321.         jc writedone2
  322.         movzx ebx,v86r_ax
  323.         add ebp,ebx
  324.         sub ecx,ebx
  325.         jbe writedone
  326.         add v86r_ds,0fffh
  327.         jmp writel
  328. writelong:
  329.         mov esi,edx
  330.         sub esi,_code32a
  331.         mov edx,ecx
  332.         mov eax,_filebufloc
  333.         add eax,_code32a
  334.         mov ebx,eax
  335.         shr eax,4
  336.         and bx,0fh
  337.         mov v86r_ds,ax
  338.         mov v86r_dx,bx
  339.         movzx ebx,_filebuflen
  340. writelongl:
  341.         mov eax,ebx
  342.         c